package com.opNaga.bpmn.panel;

import y.view.Graph2DView;
import y.view.Overview;

import javax.swing.*;
import java.awt.*;

/**
 * User: Junyi BEI
 * Date: 20/03/2012
 * Time: 17:59
 */
public class PanelSupport {
  public static JPanel createTitledPanel(JComponent content, String title) {
    JPanel panel = new JPanel();
    JLabel label = new JLabel(title);
    label.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    label.setBackground(new Color(231, 219, 182));
    label.setOpaque(true);
    label.setForeground(Color.DARK_GRAY);
    label.setFont(label.getFont().deriveFont(Font.BOLD));
    label.setFont(label.getFont().deriveFont(13.0f));
    panel.setLayout(new BorderLayout());
    panel.add(label, BorderLayout.NORTH);
    panel.add(content, BorderLayout.CENTER);
    return panel;
  }

  public static Overview createOverview(Graph2DView view, Dimension dimension) {
    Overview overview = new Overview(view);
    /* customize the overview */
    //animates the scrolling
    //blurs the part of the graph which can currently not be seen
    overview.putClientProperty("Overview.PaintStyle", "Funky");
    //allows zooming from within the overview
    overview.putClientProperty("Overview.AllowZooming", Boolean.TRUE);
    //provides functionality for navigation via keyboard (zoom in (+), zoom out (-), navigation with arrow keys)
    overview.putClientProperty("Overview.AllowKeyboardNavigation", Boolean.TRUE);
    //determines how to differ between the part of the graph that can currently be seen, and the rest
    overview.putClientProperty("Overview.Inverse", Boolean.TRUE);
    //    overview.setMinimumSize(new Dimension(200, 100));

    overview.setPreferredSize(dimension);
    //new Dimension(new Double(0.2 * contentPane.getWidth()).intValue(), 200)
    return overview;
  }
}
